package org.nahtanoj.driveutils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class DriveSync {

	public static List<String>argList;

	private static boolean findAction(String action) {
		boolean result = false;
		if (argList.contains(action)) {
			argList.remove(action);
			result = true;
		}
		return result;
	}

	public static void main(String[] args) {
		String actualRoot = "Unsync/";
		String masterRoot = "";
		String actual = "driveActual.txt";
		String master = "driveMaster.txt";
		String queue = "queue.txt";
		String masterLocation = "/c/media/Our Pictures/";

		boolean actionMaster = false;
		boolean actionActual = false;
		boolean actionQueue = false;
		boolean actionProcess = false;

		argList = new ArrayList<String>(Arrays.asList(args));
		if (argList.size() == 0) {
			usage();
		}

		actionMaster  = findAction("master");
		actionActual  = findAction("actual");
		actionQueue   = findAction("queue");
		actionProcess = findAction("process");

		if (argList.size() > 0) {
			usage();
		} else {
			try {
				if (actionMaster) {
					System.out.println("cd \"" + masterLocation +
							"\" && find <dirs> -type f -printf \"%s %p\\n\" >/c/media/DriveSync/driveMaster.txt");
				} else {
					if (actionActual) {
						new DriveUtils().getFolderMeta(actualRoot, actual);
					}
					DifferenceIdentifier di = new DifferenceIdentifier();
					if (actionQueue) {
						di.createQueue(master, masterRoot, actual, actualRoot, queue);
					}
					if (actionProcess) {
						di.processQueue(queue, masterLocation, actualRoot);
					}
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	public static void usage() {
		System.out.println("DriveSync action action1 action2 ... [actualRoot] [masterLocation]");
		System.out.println("\t where action is one of");
		System.out.println("\t master - create driveMaster.txt");
		System.out.println("\t actual - create driveActual.txt");
		System.out.println("\t queue  - create queue.txt");
		System.out.println("\t process - process queue.txt");
		System.out.println("\t actualRoot - default Unsync/");
		System.out.println("\t masterLocation - default /c/media/Our Pictures/");
	}

}
